from acllite_resource import AclLiteResource
from acllite_imageproc import AclLiteImageProc
from acllite_imageproc import AclLiteImage

# 创建acl管理对象
aclResource = AclLiteResource()
aclResource.init()

# 创建dvpp处理对象
dvppResource = AclLiteImageProc(aclResource)

# 创建图片对象
input_path="./data/dog1_1024_683.jpg"
cpu_jpg_image = AclLiteImage(input_path)

# 把JPG数据拷贝到NPU中
npu_jpg_image = cpu_jpg_image.copy_to_dvpp()

# 把图片转换成YUV的格式
npu_yuv_image = dvppResource.jpegd(npu_jpg_image)
print(npu_yuv_image.width, npu_yuv_image.height, npu_yuv_image.alignWidth, npu_yuv_image.alignHeight)

# 保存YUV的图片下来查看
npu_yuv_image_name = str(npu_yuv_image.alignWidth) + "x" + str(npu_yuv_image.alignHeight) + "_NV12.yuv"
npu_yuv_image.save(npu_yuv_image_name)

# resize图片
npu_yuv_image2 = dvppResource.resize(npu_yuv_image, 532, 413)
print(npu_yuv_image2.width, npu_yuv_image2.height, npu_yuv_image2.alignWidth, npu_yuv_image2.alignHeight)

# 保存YUV的图片下来查看
npu_yuv_image_name = str(npu_yuv_image2.alignWidth) + "x" + str(npu_yuv_image2.alignHeight) + "_NV12.yuv"
npu_yuv_image2.save(npu_yuv_image_name)
